package com.ruoyi.business.runner;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.business.domain.ResearchPlan;
import com.ruoyi.business.service.IResearchPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liutao
 * @version 1.0
 * @description: TODO
 * @date 2024/5/16 11:11
 */
@Slf4j
@Component
public class CacheRunner implements ApplicationRunner {

    @Resource
    private IResearchPlanService researchPlanService;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("[CacheRunner][加载计划图层缓存......]");
        loadPlanLayerCache();
    }

    public void loadPlanLayerCache() {
        List<ResearchPlan> list = researchPlanService.list();
        if (CollUtil.isNotEmpty(list)) {
            for (ResearchPlan researchPlan : list) {
                researchPlanService.getPlanLayer(researchPlan.getId());
            }
        }
    }
}
